// https://leetcode.cn/problems/summary-ranges/
// Created by ade on 2022/7/25.
//
#include <iostream>
#include <vector>


using namespace std;

class Solution {
public:
    vector <string> summaryRanges(vector<int> &nums) {
        int len = nums.size();
        if (len == 0) return {};
        if (len == 1) return {to_string(nums[0])};
        vector <string> res = {};
        int i = 0;
        int start = 0;
        for (i = 0; i < len - 1; i++) {
            start = nums[i];
            while (i < len - 1 && (long long)((long long)nums[i + 1] - (long long)nums[i]) == 1) {
                i++;
            }
            if (nums[i] == start) {
                res.push_back(to_string(start));
            } else {
                res.push_back(to_string(start) + "->" + to_string(nums[i]));
            }
        }
        if (i == len - 1) {
            res.push_back(to_string(nums[i]));
        }

        return res;
    }
};

int main() {
    Solution so;
    vector<int> a = {0, 1, 2, 4, 5, 7, 8};
    auto res = so.summaryRanges(a);
    for (auto i : res) {
        cout << i << ",";
    }
    cout << endl;
    return 0;

}